#include <iostream>

using namespace std;

class Receiver {
public:
    virtual ~Receiver() = default;

public:
    virtual void action() = 0;
};

class Command {
public:
    virtual ~Command() = default;

public:
    virtual void execute() = 0;
};

class Invoker {
public:
    explicit Invoker(Command *command) : command(command) {}

    virtual ~Invoker() {
        delete command;
    }

private:
    Command *command = nullptr;

public:
    void invoke() {
        command->execute();
    }
};

class ReceiverA : public Receiver {
public:
    ~ReceiverA() override = default;

public:
    void action() override {
        cout << "Receiver A Do Some Thing!" << endl;
    }
};

class ReceiverB : public Receiver {
public:
    ~ReceiverB() override = default;

public:
    void action() override {
        cout << "Receiver B Do Some Thing!" << endl;
    }
};

class ConcreteCommand : public Command {
public:
    explicit ConcreteCommand(Receiver *receiver) : receiver(receiver) {}

    ~ConcreteCommand() override {
        delete receiver;
    }

private:
    Receiver *receiver = nullptr;

public:
    void execute() override {
        receiver->action();
    }
};

void test01() {
    Receiver *receiver = nullptr;
    Command *command = nullptr;
    Invoker *invoker = nullptr;

    receiver = new ReceiverA();
    command = new ConcreteCommand(receiver);
    invoker = new Invoker(command);

    invoker->invoke();

    delete command, invoker;

    cout << endl;
}

void test02() {
    Receiver *receiver = nullptr;
    Command *command = nullptr;
    Invoker *invoker = nullptr;

    receiver = new ReceiverB();
    command = new ConcreteCommand(receiver);
    invoker = new Invoker(command);

    invoker->invoke();

    delete command, invoker;

    cout << endl;
}

int main() {
    test01();

    test02();
}
